Object-Oriented Programming Introduction
Outline
"O O It’s magic"
More than just syntax of an O-O language.
Procedural programming practice can be a hindrance.
Requires more discipline, often enforced in the language.
OOP is analysis + design + programming.
In 1625, King Gustav wanted to sail the oceans wide,
He called for a shipwright to build the vessel right.
Hybertszoon was his name but their ideas were not the same,
So the Vasa lies at the bottom of the ocean as her only fame.
Where’s the Power?
Goooooalllllllllll
Better software developed faster.
"Don’t know much about history"
The language of 1’s and 0’s
Very low level, hard to program in but great speed.
"I want to know machine language". This is much different the wanting to learn machine language.
Same speed as machine code but a little easier to program in.
Procedure must be followed in order for the machine to function
Rudimentary code-reuse and distinction between the what vs. how of a problem.
Crime Watch neighborhood
The idea here is to have variables only within the procedures that need them. However, when sharing is required this mechanism does not work.
Close but no cigar
Routines linked in from outside a program to do certain tasks.
Achieved encapsulation of code and data but it broke down in instances where more than one structure that the module represented was needed.
"In theory Communism works" – Homer J. Simpson
Extended modules with the ability of having more than one instance of itself.
From C to O-O
O-O comes from real-world philosophical concepts.
Who?
In linguistics there is a hypothesis that the language in which an idea or thought is expressed colors the nature of the thought.
Sapir and Whorf went further, and claimed that there were thoughts one could have in one language that could not ever occur, could not even be explained, to somebody thinking in a different language.
It’s called marketing
The medium is the message states that the means of communications has a greater influence on people than the information itself.
Link this with Sapir-Whorf.
The pen may be mightier than the sword but at any single instance the sword has a definite advantage.
Using real-world concepts to solve a program that maps into a programming style and language.
No, this is NOT some liberal theology
Opposite of Sapir – Whorf
The real-world is "object oriented". Thinking and programming object-oriented make the problem solving job easier.
Link this with the power of the metaphor.
People have always tried to use computers to solve problems that were just a little more difficult than they knew how to solve.
The problem is not the algorithm or even that projects are large it is because of the numerous interactions.
O-O helps to manage this, however programming is still difficult because we are trying to do more in the software.
O-O is a new system of organizing code.
Match Problem Domain with Problem Solving Style
A match made in heaven. Probably Not.
It is the best mainstream solution at this time.
Imperative vs. Object-Oriented
Paradigm – NOT 20 cents (a pair of dimes). It is a model.
To Do
"Pigeon-hole" computing. Doesn’t map to real-world easily.
Fails because data is separate from functions, data is often global, and access to the data is uncontrolled and unpredictable. Testing and debugging is in turn difficult.
Indicative: To Be
Recursive design
Succeeds because code and data combined, access to data is controlled and predictable, and it maps more closely to the real world.
Don’t build your house on sinking sand
A PIE
Abstraction
Polymorphism
Inheritance
Encapsulation
A whole slew of new words and definitions
What is an object?
Contains methods and attributes
Communicates with messages
Basic element of code organization
Each instance of an object is unique
Has a life-cycle: birth, life and death
All objects have class
Class in an object definition
The terms object and class are used differently depending on the context, thus confusion.
An incarnation
Refers to an object. Most likely implemented as a "pointer" – a variable containing an address of where an specific instance of an object is located at.
What are you like?
Traits, information, returns a value doesn’t perform program logic.
What can you do?
Perform program logic.
What do you communicate?
Like a function call.
How do you communicate?
Public method signatures
Someone using your object will program to the interface so make it long-lasting.
You can’t use your senses to understand a thought. Therefore, is a thought real?
Hide the details so as to hide complexity so that you can deal with a topic at a particular level.
To enclose
Data and logic together.
Overloading – similar method call, similar meaning
Overriding – same method call, different meaning
Many Meanings
Overloading is the writing of multiple functions with the same name.
Polymorphism goes further in that you can write one function to operate of many different object types.
Passing on the genes
"Is-A" relationship
Organization technique. General to specific
No, this is NOT English 101
"Has-A" relationship
Aggregation - Whole-part from the perspective of the whole
Link – Peer-to-peer
Association – parts that make up a whole
With some art you can only say, "Oh, what a lovely frame"
The inverse of a code library
Kay’s description of Object-Oriented programming
Everything is an object
Objects perform computation by making requests of each other through the passing of messages
It is better to give than to receive
Binding time
Elements of OOP – Recursive Design
Every object has it's own memory, which consists of other objects
Non-interference
Every object is an instance of a class. A class groups similar objects.
The class is the repository for behavior associated with an object.
Classes are organized into a singly-rooted tree structure, called an inheritance hierarchy
Overloading these circuits is good
O-O Design Why start with design?
Can’t we just start coding?
All good systems have a design
Whatever methodology is employed should be one that is usable and actually used.
How would you design an object?
Code, run, debug, repeat
Using the right tool for the jobs works so much better